/**
 * 配合通用的接口对 Vue 全局调用封装：Vue.use(api)
 * 在组件中可以直接用 this.$api 调用
 */

import { exportData, exportUrl } from '@/common/api/download'
import {
  getData,
  getDataFromId,
  getDataQuery,
  updateData,
  updateDataBody,
  updateBatch,
  addData,
  addBatch,
  deleteData,
  deleteDataQuery,
  deleteDataBody,
  relatedBatch,
  relatedDelete,
  relatedUpdate,
} from '@vimi/utils-api'

const install = Vue => {
  if (install.installed) {
    return
  }
  install.installed = true

  Object.defineProperties(Vue.prototype, {
    $api: {
      get() {
        return {
          getData,
          getDataFromId,
          getDataQuery,
          updateData,
          updateDataBody,
          updateBatch,
          addData,
          addBatch,
          deleteData,
          deleteDataQuery,
          deleteDataBody,
          relatedBatch,
          relatedDelete,
          relatedUpdate,
          exportData,
          exportUrl,
        }
      },
    },
  })
}

export default install
